﻿//********************************************************************************************
//** 					        NoSleepHD v1.0                     	                        **
//**A Simple program to stop your external hard-drive from going ot Auto-Sleep mode.        **
//********************************************************************************************
//**    SIMILAR     (c) 2009 Ashutosh Agarwal. All Rights Reserved      			        **
//**    Version     1.0.0	                                         		            	**
//**    Notes                                                        		            	**
//********************************************************************************************

//How to use the program:

//1. Select any drive on your external hard disk OR a folder on your external hard disk drive.
//2. Set the timer. (10 Minutes Recommended)
//3. Press 'Start NoSleep Mode'.

//And that is it! No more irritating waiting/connection problem with your external hard disk.

//You could stop the program if you want to. (Which would allow the drive to go to auto-sleep 
//after a few minutes.

//You could also choose the applicaiton to sit in the System Tray or simply minimized.


//Any Comments, Questions, Suggestions, Requests should go to: agarwal@hotmail.co.uk

//Product Home Page: http://nosleephd.codeplex.com/

//Thank you for using the program.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Timers;


namespace NoSleepHD
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        private void Form1_Load(object sender, EventArgs e)
        {

        }
        int i = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog tree = new FolderBrowserDialog();
            tree.RootFolder = Environment.SpecialFolder.MyComputer;
            tree.ShowNewFolderButton = false;
            tree.Description = "Please Select any Drive OR Folder on Your External hard Drive";
            tree.ShowDialog();
            label2.Text = tree.SelectedPath.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (label2.Text == "Not Monitoring")
            {
                MessageBox.Show("Please Select any external Hard Drive/Folder first");
            }
            else
            {
                timer1.Start();
                label8.ForeColor = Color.Green;
                label8.Text = "ON";
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled == false)
            {
                //MessageBox.Show("Please Start the timer first to Stop it :)");
            }
            else
            {
                timer1.Stop();
                label8.ForeColor = Color.Red;
                label8.Text = "OFF";
            }

        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            i = i + 1;
            if (i >= (numericUpDown1.Value * 6))
            {
                // Touch File and reset i's value.
                FileStream fs = new FileStream(label2.Text + "test.txt", FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);
                sw.Write("NoSleepHD Mode Tick! By Ashutosh Agarwal - agarwal@hotmail.co.uk");
                sw.Close();
                fs.Close();
                i = 0;
            }


        }

        private void button4_Click(object sender, EventArgs e)
        {
            Hide();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Show();
            WindowState = FormWindowState.Normal;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MessageBox.Show("Please forward any Questions, Comments, Suggestions, Requests to: " +
                            "\n\nagarwal@hotmail.co.uk\n\nThank You for Using the Program",
                            "NoSleepHD v1.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("A Simple program which writes an empty text file every few minutes to " +
                            "your external hard disk drive to keep it from going into auto-sleep mode." +
                            "\nUsually auto sleep timer in external hard disks is 10 Minutes.", "NoSleepHD v1.0 | By - Ashutosh Agarwal",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

        }

    }
}
